/** @format */
/* eslint-disable */
export default function(verifys, value) {
  let temp = verifys.split('|');
  let exg;
  if (temp.includes('required')) {
    exg = /[\S]+/;
    if (!exg.test(value)) {
      return '为必填项不能为空';
    }
  }
  if (temp.includes('xssVerify')) {
    //去掉了_     \_+|
    exg = /\~+|\!+|\@+|\#+|\$+|\%+|\^+|\&+|\*+|\(+|\)+|\++|\{+|\}+|\|+|\:+|\"+|\<+|\>+|\?+|\`+|\-+|\=+|\[+|\]+|\\+|\;+|\'+|\/+|\~+|\！+|\@+|\#+|\￥+|\%+|\…+|\…+|\&+|\*+|\（+|\）+|\—+|\—+|\++|\{+|\}+|\|+|\：+|\”+|\《+|\》+|\？+|\·+|\-+|\=+|\【+|\】+|\、+|\；+|\‘+|\，+|\。+|\、+|\～+|\！+|\＠+|\＃+|\￥+|\％+|\……+|\＆+|\×+|\（+|\）+|\——+|\＋+|\｛+|\｝+|\｜+|\：+|\“+|\《+|\》+|\？+|\·+|\－+|\＝+|\【+|\】+|\＼+|\；+|\’+|\，+|\。+|\、+|\＄+|\＾+|\＊+|\＿+|\］+|\［+|\＂+|\＇+|\／+|\．+|\＞+|\＜+|\｀+|[\r\n]+|(\b)select(\b)|(\b)update(\b)|(\b)insert(\b)|(\b)delete(\b)|(\b)declare(\b)|(\b)exec(\b)|(\b)dbcc(\b)|(\b)alter(\b)|(\b)drop(\b)|(\b)create(\b)|(\b)backup(\b)|(\b)if(\b)|(\b)else(\b)|(\b)end(\b)|(\b)and(\b)|(\b)or(\b)|(\b)add(\b)|(\b)set(\b)|(\b)open(\b)|(\b)close(\b)|(\b)use(\b)|(\b)begin(\b)|(\b)retun(\b)|(\b)as(\b)|(\b)go(\b)|(\b)exists(\b)|(\b)script(\b)|(\b)window(\b)|(\b)location(\b)|(\b)alert(\b)|(\b)eval(\b)|(\b)onblur(\b)|(\b)onfocus(\b)|(\b)vbscript(\b)|(\b)document(\b)|(\b)cookie(\b)|(\b)join(\b)|(\b)union(\b)|(\b)truncate(\b)|(\b)expression(\b)|(\b)iframe(\b)|(\b)like(\b)|(\b)table(\b)|(\b)master(\b)|(\b)mid(\b)|(\b)count(\b)|(\b)from(\b)|(\b)oncontrolselect(\b)|(\b)oncopy(\b)|(\b)oncut(\b)|(\b)ondataavailable(\b)|(\b)ondatasetchanged(\b)|(\b)ondatasetcomplete(\b)|(\b)ondblclick(\b)|(\b)ondeactivate(\b)|(\b)ondrag(\b)|(\b)ondragend(\b)|(\b)ondragenter(\b)|(\b)ondragleave(\b)|(\b)ondragover(\b)|(\b)ondragstart(\b)|(\b)ondrop(\b)|(\b)onerror(\b)|(\b)onerroupdate(\b)|(\b)onfilterchange(\b)|(\b)onfinish(\b)|(\b)onfocus(\b)|(\b)onfocusin(\b)|(\b)onfocusout(\b)|(\b)onhelp(\b)|(\b)onkeydown(\b)|(\b)onkeypress(\b)|(\b)onkeyup(\b)|(\b)onlayoutcomplete(\b)|(\b)onload(\b)|(\b)onlosecapture(\b)|(\b)onmousedown(\b)|(\b)onmouseenter(\b)|(\b)onmouseleave(\b)|(\b)onmousemove(\b)|(\b)onmousout(\b)|(\b)onmouseover(\b)|(\b)onmouseup(\b)|(\b)onmousewheel(\b)|(\b)onmove(\b)|(\b)onmoveend(\b)|(\b)onmovestart(\b)|(\b)onabort(\b)|(\b)onactivate(\b)|(\b)onafterprint(\b)|(\b)onafterupdate(\b)|(\b)onbefore(\b)|(\b)onbeforeactivate(\b)|(\b)onbeforecopy(\b)|(\b)onbeforecut(\b)|(\b)onbeforedeactivate(\b)|(\b)onbeforeeditocus(\b)|(\b)onbeforepaste(\b)|(\b)onbeforeprint(\b)|(\b)onbeforeunload(\b)|(\b)onbeforeupdate(\b)|(\b)onblur(\b)|(\b)onbounce(\b)|(\b)oncellchange(\b)|(\b)onchange(\b)|(\b)onclick(\b)|(\b)oncontextmenu(\b)|(\b)onpaste(\b)|(\b)onpropertychange(\b)|(\b)onreadystatechange(\b)|(\b)onreset(\b)|(\b)onresize(\b)|(\b)onresizend(\b)|(\b)onresizestart(\b)|(\b)onrowenter(\b)|(\b)onrowexit(\b)|(\b)onrowsdelete(\b)|(\b)onrowsinserted(\b)|(\b)onscroll(\b)|(\b)onselect(\b)|(\b)onselectionchange(\b)|(\b)onselectstart(\b)|(\b)onstart(\b)|(\b)onstop(\b)|(\b)onsubmit(\b)|(\b)onunload(\b)/;
    if (exg.test(value)) {
      return '存在特殊字符或特殊单词';
    }
  }
  if (temp.includes('number')) {
    if (isNaN(value)) {
      return '只能填写数字';
    }
  }
  if (
    temp.findIndex(item => {
      return item.includes('-');
    }) >= 0
  ) {
    let arr = temp
      .find(item => {
        return item.includes('-');
      })
      .split('-');
    arr.sort((a, b) => a - b);
    let maxLength = arr[arr.length - 1];
    let minLength = arr[0];
    if (value.length < minLength / 1) {
      return '输入长度不能小于' + minLength;
    } else if (value.length > maxLength / 1) {
      value = value.slice(0, maxLength);
      return '输入长度不能大于' + maxLength;
    }
  }
  if (
    temp.findIndex(item => {
      return item.startsWith('.');
    }) >= 0
  ) {
    let arr = temp
      .find(item => {
        return item.startsWith('.');
      })
      .substring(1);
    arr = Number(arr);
    exg = new RegExp(`^(?=([0-9]{1,10}$|[0-9]{1,7}\.))(0|[1-9][0-9]*)(\.[0-9]{1,${arr}})?$`);
    if (!exg.test(value)) {
      return `最多输入${arr}位小数`;
    }
  }
  if (temp.includes('date')) {
    exg = /^(\d{4})[-\/](\d{1}|0\d{1}|1[0-2])([-\/](\d{1}|0\d{1}|[1-2][0-9]|3[0-1]))*$/;
    if (!exg.test(value)) {
      return '日期格式不正确';
    }
  }
  if (temp.includes('email')) {
    exg = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
    if (!exg.test(value)) {
      return '邮箱格式不正确';
    }
  }
  if (temp.includes('idCard')) {
    exg = /^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/;
    if (!exg.test(value)) {
      return '身份证号格式不正确';
    }
  }
  if (temp.includes('phone')) {
    exg = /^[1](([3][0-9])|([4][5-9])|([5][0-3,5-9])|([6][5,6])|([7][0-8])|([8][0-9])|([9][1,8,9]))[0-9]{8}$/;
    if (!exg.test(value)) {
      return '手机号码格式不正确';
    }
  }
  if (temp.includes('url')) {
    exg = /(^#)|(^http(s*):\/\/[^\s]+\.[^\s]+)/;
    if (!exg.test(value)) {
      return '网络连接格式不正确';
    }
  }
  if (temp.includes('userName')) {
    exg = /^[a-zA-Z][a-zA-Z0-9_]{4,15}$/;
    if (!exg.test(value)) {
      return '必须是5-16位长度，由字母开头，包含字母数字下划线';
    }
  }
  if (temp.includes('coding')) {
    exg = /^[a-z_]+$/;
    if (!exg.test(value)) {
      return '只能包含小写字母下划线';
    }
  }
  return '';
}
